package com.fx.common;

import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Node;


public abstract class AbsButtonActionHandler<T extends Node,R extends Event> implements EventHandler<R> {

    private void handleOnActionMenu(T item){
        if(item.getUserData() == null){
            return;
        }
        assert item.getUserData() instanceof ButtonController;
        final ButtonController controller = (ButtonController) item.getUserData();
        if(controller.canClick()){
            controller.perform();
        }
    }

    @Override
    public void handle(R event) {
        assert event.getSource() != null;
        handleOnActionMenu((T) event.getSource());
    }

    public abstract void setupButtonAction(T button);

}
